<?php
namespace Unicom\Controller;
use Think\Controller;

class ChannelController extends AdminController {
	public function list_() {
		layout(false);
		$product = I('param.product', 1);

		$model = M('wa.auth_key', 'wa_');
		$data = $model->where(array('product' => $product))->order('id desc')->select();
		$this->assign('data', $data);
		$this->assign('product',$product);

		$this->display();
	}

	public function edit_() {
		layout(false);
		$model = M('wa.auth_key', 'wa_');
        $product=I('param.product');
        $this->assign('product',$product);
		if (IS_POST) {

			$id = I('param.id', 0);
			$name = I('param.name', '');
			$track_id = I('param.track_id', '');
			$content_id = I('param.content_id', '');
			$sync_url = I('param.sync_url', '');
			if ($sync_url == "") {
				$this->error('参数不对');
			}

			$model->where('id=' . $id)->setField(array('name' => $name, 'sync_url' => trim($sync_url), 'track_id' => $track_id, 'content_id' => $content_id));
			$this->success('修改成功');

		} else {
			$id = I('param.id', 0);

			$data = $model->where('id=' . $id)->find();
			$this->assign('data', $data);
			$this->display();
		}

	}

	public function add_() {
		layout(false);
		if (IS_POST) {
			$data = I('param.');
			$data['create_at'] = time();
			$data['api_key'] = md5(uniqid());
			$data['security_key'] = md5(md5(uniqid()));
			$model = M('wa.auth_key', 'wa_');
			if ($model->add($data)) {
				$this->success('成功');
			} else {
				$this->error("失败");
			}

		} else {
		    $product=I('param.product');
		    $this->assign('product',$product);
			$this->display();
		}

	}
	//模拟发送
	public function send_($id,$product) {


		$model = M('wa.auth_key', 'wa_');
		$url = $model->where('id=' . $id)->find()['sync_url'];

        $data["mobile"] = "18588520588";
        $data["code"] = "$id#500#100";
        $data["content"] = "100";
        $data["fee"] = "500";
        $data['payid']="small18050000034";
        $data['paytime']="20180524153212";
        $data['spnumber']="10690758871311";

        $ret=send_test($url,$data);
        echo "模拟日志：".$ret["url"]."\n"."同步返回:".$ret["result"];


		//$this->success($ret);

	}

}